$(document).ready(function () {

    //Language div's opening and closing codes.
    $(".languageMainLink").click(function (e) {
        if ($(".languageBoxMenuDiv").is(':hidden')) {
            $(".languageBoxMenuDiv").slideDown(200);
        }
        else {
            $(".languageBoxMenuDiv").slideUp(200);
        }
        $('body').one('click', function () {
            $(".languageBoxMenuDiv").slideUp(200);
        });
        e.stopPropagation();
    });
    //Language div's opening and closing codes.---END

    //Writing the selected language to language div header.
    $(".languageBoxMenuDiv div").click(function () {
        var spanValue = $(this).children("span").text()
        $("img.languageFlag").attr('src', $(this).children("img").attr('src'));
        $("span.languageSpan").text(spanValue);
    });
    //Writing the selected language to language div header.---END


    //MENU Hover and adjustments
    $(".menuMainHeader").hover(
	  function () {
	      $(this).prev("li").children("a").addClass("noBg");
	      $(this).find(".menuContent").show();
	      $(this).children(".menuMainHeaderLink").addClass("menuMainHeaderLinkHover");
	  },
	  function () {
	      $(this).prev("li").children("a").removeClass("noBg")
	      $(this).find(".menuContent").hide();
	      $(this).children(".menuMainHeaderLink").removeClass("menuMainHeaderLinkHover");
	  }
	);

    $(".menuFirstHeader a").hover(function () {
        $(this).children('img').attr("src", "/content/themes/default/img/menu/menuHomeHover.png");
    },
	  function () {
	      $(this).children('img').attr("src", "/content/themes/default/img/menu/menuHome.png");
	  }
	);
    //MENU Hover and adjustments ---END

    //branches 
    $(".branchesMapTopList ul li a").hover(
	  function () {
	      var branchesTopCityDiv = $(this).parents("li").attr("class")
	      branchesTopCityDiv = branchesTopCityDiv.substring(0, branchesTopCityDiv.indexOf("_"));
	      $("." + branchesTopCityDiv + "_branchesMap").find(".branchesCityDivContent").stop(true, true).fadeIn();
	  },
	  function () {
	      var branchesTopCityDiv = $(this).parents("li").attr("class")
	      branchesTopCityDiv = branchesTopCityDiv.substring(0, branchesTopCityDiv.indexOf("_"));
	      $("." + branchesTopCityDiv + "_branchesMap").find(".branchesCityDivContent").stop(true, true).hide();
	  }
	);

    $(".branchesCityDiv a").hover(
	  function () {
	      $(this).children(".branchesCityDivContent").stop(true, true).fadeIn();
	  },
	  function () {
	      $(this).children(".branchesCityDivContent").hide();
	  }
	);

    //branches tabs2
    $('.branchesTabContent').hide(); // Hide all divs
    $('.branchesTabContents .branchesTabContent:first').show(); // Show the first div
    $('.branchesTabsHeaders div:first').addClass('branchesTabsHeaderDivActive'); // Set the class for active state
    $('.branchesTabsHeaders div a').click(function () { // When link is clicked
        $('.branchesTabsHeaders div').removeClass('branchesTabsHeaderDivActive'); // Remove active class from links
        $(this).parent().addClass('branchesTabsHeaderDivActive'); //Set parent of clicked link class to active

        var currentTab = $(this).attr('href'); // Set currentTab to value of href attribute
        $('.branchesTabContent').hide(); // Hide all divs
        $(currentTab).show(); // Show div with id equal to variable currentTab
        return false;
    });
    //branches ---END




});
